<?php
require('io/FileOp.php');
global $xml;
$xml=simplexml_load_file('HelloMIDlet.vmd');

HTMLFormVMD();

function HTMLFormVMD(){
	
	global $content,$xml;
	OpenFile('a.html');
	/************************** Form ***********************************/	
	$subComponents = $xml->Document->Component;
	foreach($subComponents->Component as $component){
		
		$property = $component->Properties->Property;			
		
		switch($component['typeID']){		
			case 'C#DisplayablesCategory';							
				foreach($component->Component as $comp){
					if($comp['typeID']=='Cjavax.microedition.lcdui.Form'){
						writeFile("<form action=\"\" method=\"post\">");
						foreach($comp->Component as $c){							
							switch($c['typeID']){
								case 'Cjavax.microedition.lcdui.TextField':
									foreach($c->Property as $property){
										if($property['name']=='label'){
											$b = $property['value'];
											//print_r($property['value']);
										}
										if($property['name']=='instanceName'){
											$input = '<input name="'.substr($property['value'],1).'" type="text" value="" />';
										}									
									}
									writeFile($b.$input);																				
								break;
								case 'Cjavax.microedition.lcdui.ChoiceGroup':
									foreach($c->Property as $property){
											
											if($property['name']=='choiceType'){												
												echo $property['value'];
												if($property['value']=='V1'){	//Exclusive or radio
													foreach($c->Component as $cc){
														writeFile(substr($cc->Property['value'],1));
														writeFile("<input type=\"radio\" name=\"$name\" value=\"".substr($cc->Property['value'],1)."\"/>");
													}
												}else if($property['value']=='V2'){	//multiple or checkbox
													foreach($c->Component as $cc){
														writeFile(substr($cc->Property['value'],1));
														writeFile("<input type=\"checkbox\" name=\"$name\" value=\"".substr($cc->Property['value'],1)."\"/>");
													}
												}else if($property['value']=='V4'){	//Popup or select
													writeFile("<select name=\"$name\">");												
													foreach($c->Component as $cc){
														writeFile("<option value=\"".substr($cc->Property['value'],1)."\">".substr($cc->Property['value'],1)."</option>");
													}
													writeFile("</select>");
												}
											}else if($property['name']=='instanceName'){
												$name = substr($property['value'],1);
											}
										}
									
								break;
							}							
						}
						writeFile("</form>");
					}
				}
				
				//writeFile($property['value']);
			break;
			
			case 'java.awt.Button':			
				$eventHandler = $component->Events->EventHandler;
				$b = '<button name="'.$component['name'].'" onclick="return '.$eventHandler['handler'].'();">';			
				$b.=$property['value'];
				writeFile($b);
				writeFile('</button>');			
				writeFile('<script type="text/javascript">');
				writeFile('function '.$eventHandler['handler'].'(){');
				writeFile('}');
				writeFile('</script>');
			break;
		}
		
	}
	CloseFile();
}
?>